import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/home/index';

Vue.use(Router)
export const constantRoutes = [
  {
    path: '/',
    redirect: '/index',
  },
  {
    path: '/index',
    component: Home,
    meta: {
      title: process.env.VUE_APP_TITLE,
    },
  },
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
